import { ref } from 'vue'
import { queryMerchantTypepi } from '@/api/statistics'

// 全局商户类型列表（懒加载 + 缓存）
export const merchantTypes = ref([])
let loaded = false
let loading = false

export const ensureMerchantTypes = async () => {
  if (loaded || loading) return merchantTypes.value
  loading = true
  try {
    const res = await queryMerchantTypepi()
    merchantTypes.value = Array.isArray(res?.data) ? res.data : []
    loaded = true
  } finally {
    loading = false
  }
  return merchantTypes.value
}